package com.smart.campus.web.controller.school;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.smart.campus.common.annotation.Log;
import com.smart.campus.common.enums.BusinessType;
import com.smart.campus.school.domain.ClassTeacherRelation;
import com.smart.campus.school.service.IClassTeacherRelationService;
import com.smart.campus.common.core.controller.BaseController;
import com.smart.campus.common.core.domain.AjaxResult;
import com.smart.campus.common.utils.poi.ExcelUtil;
import com.smart.campus.common.core.page.TableDataInfo;

/**
 * 班级老师关系Controller
 * 
 * @author Zhihe.Li
 * @date 2020-11-25
 */
@Controller
@RequestMapping("/school/relation")
public class ClassTeacherRelationController extends BaseController
{
    private String prefix = "school/relation";

    @Autowired
    private IClassTeacherRelationService classTeacherRelationService;

    @GetMapping()
    public String relation(Long classId, ModelMap mmap)
    {
        mmap.put("classId",classId);
        return prefix + "/relation";
    }

    /**
     * 查询班级老师关系列表
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ClassTeacherRelation classTeacherRelation)
    {
        startPage();
        List<ClassTeacherRelation> list = classTeacherRelationService.selectClassTeacherRelationList(classTeacherRelation);
        return getDataTable(list);
    }

    /**
     * 导出班级老师关系列表
     */
    @Log(title = "班级老师关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ClassTeacherRelation classTeacherRelation)
    {
        List<ClassTeacherRelation> list = classTeacherRelationService.selectClassTeacherRelationList(classTeacherRelation);
        ExcelUtil<ClassTeacherRelation> util = new ExcelUtil<ClassTeacherRelation>(ClassTeacherRelation.class);
        return util.exportExcel(list, "relation");
    }

    /**
     * 新增班级老师关系
     */
    @GetMapping("/add")
    public String add(Long classId, ModelMap mmap)
    {
        mmap.put("classId",classId);
        return prefix + "/add";
    }

    /**
     * 新增保存班级老师关系
     */
    @Log(title = "班级老师关系", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ClassTeacherRelation classTeacherRelation)
    {
        return toAjax(classTeacherRelationService.insertClassTeacherRelation(classTeacherRelation));
    }

    /**
     * 修改班级老师关系
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ClassTeacherRelation classTeacherRelation = classTeacherRelationService.selectClassTeacherRelationById(id);
        mmap.put("classTeacherRelation", classTeacherRelation);
        return prefix + "/edit";
    }

    /**
     * 修改保存班级老师关系
     */
    @Log(title = "班级老师关系", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ClassTeacherRelation classTeacherRelation)
    {
        return toAjax(classTeacherRelationService.updateClassTeacherRelation(classTeacherRelation));
    }

    /**
     * 删除班级老师关系
     */
    @Log(title = "班级老师关系", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(classTeacherRelationService.deleteClassTeacherRelationByIds(ids));
    }
}
